﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevelopStudio.Basic;
using SharpSvn;
using System.IO;
using CommonBasic = DevelopStudio.Common.Basic;
using CommonManage = DevelopStudio.Common.Manage;
using System.Diagnostics;

namespace DevelopStudio.Control.FormPage
{
    public partial class CheckModificationSimpleForm : Form
    {
        private int selectedIndex = -1;

        public CheckModificationSimpleForm()
        {
            InitializeComponent();
        }

        private void CheckModificationSimpleForm_Load(object sender, EventArgs e)
        {
            List<WorkingCopyInfo> temp = Utility.Settings.WorkingCopies.ToList();

            if (temp.Count <= 0)
            {
                this.Close();
                return;
            }
            else if (temp.Count == 1)
            {
                this.Visible = false;
                Process tempProcess = Process.Start("TortoiseProc.exe", @"/command:repostatus /path:" + temp[0].Path + " /closeonend:0");

                tempProcess.WaitForExit();
                this.Close();
                return;
            }

            temp.Insert(0, new WorkingCopyInfo() { Path = Properties.Resources.PleaseSelect});

            this.comboBoxPlatform.DataSource = temp;
            this.comboBoxPlatform.DisplayMember = "Path";
            this.comboBoxPlatform.ValueMember = "Path";
            return;
        }

        private void comboBoxPlatform_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.selectedIndex == this.comboBoxPlatform.SelectedIndex)
            {
                return;
            }

            this.selectedIndex = this.comboBoxPlatform.SelectedIndex;

            if (this.selectedIndex == 0)
            {
                return;
            }

            this.Visible = false;

            WorkingCopyInfo workPlatform = this.comboBoxPlatform.SelectedItem as WorkingCopyInfo;

            Process tempProcess = Process.Start("TortoiseProc.exe", @"/command:repostatus /path:" + workPlatform.Path + " /closeonend:0");

            tempProcess.WaitForExit();
            this.Close();
        }
    }
}
